#include<bits/stdc++.h>
using namespace std;
namespace fastio
{
	constexpr int S1=1<<20;
	char buf1[S1],*l1,*r1;
	inline char getc()
	{
		return ((l1==r1&&(r1=(l1=buf1)+fread(buf1,1,S1,stdin)),l1!=r1)?*l1++:EOF);
	}
	template<typename T=int>inline T read()
	{
		T x=0,y=1;
		char c=getc();
		for(;c<'0'||c>'9';c=getc())
			if(c=='-')
				y=-1;
		for(;c>='0'&&c<='9';c=getc())
			x=c-'0'+x*10;
		return x*y;
	}
	constexpr int S2=1<<20;
	char buf2[S2],*l2=buf2;
	inline void putc(char c)
	{
		l2==buf2+S2&&(fwrite(buf2,1,S2,stdout),l2=buf2),*l2++=c;
	}
	int st[22];
	template<typename T>inline void write(T x,char end='\n')
	{
		if(x<0)
			putc('-'),x=-x;
		int tp=0;
		do
			st[++tp]=x%10;
		while(x/=10);
		while(tp)
			putc(st[tp--]+'0');
		if(end)
			putc(end);
	}
	struct end
	{
		~end()
		{
			fwrite(buf2,1,l2-buf2,stdout);
		}
	}ender;
}
using fastio::getc;
using fastio::read;
using fastio::putc;
using fastio::write;
constexpr long long INF=0x3f3f3f3f3f3f3f3f;
constexpr int MN=200005,V=1000000;
int n,a[MN];
long long del,mx[V+5],fmx;
inline void work()
{
	n=read();
	mx[0]=del=fmx=0;
	for(int i=1;i<=V;i++)
		mx[i]=-INF;
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
		long long t=max(fmx,mx[a[i]]+a[i])+del;
		if(a[i]==a[i-1])
			del+=a[i];
		mx[a[i-1]]=max(mx[a[i-1]],t-del);
		fmx=max(fmx,t-del);
	}
	printf("%lld\n",fmx+del);
}
int main()
{
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	int T=read();
	while(T--)
		work();
	return 0;
}